package com.tianya.portal.blog.service.impl;

import com.tianya.common.web.utils.StringUtils;
import com.tianya.portal.blog.domain.BlogNewsRecall;
import com.tianya.portal.blog.mapper.BlogNewsRecallMapper;
import com.tianya.portal.blog.service.IBlogNewsRecallService;
import com.tianya.portal.system.domain.SysFile;
import com.tianya.portal.system.mapper.SysFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 朝花夕拾Service业务层处理
 *
 * @author tianya
 * @date 2023-05-10
 */
@Service
public class BlogNewsRecallServiceImpl implements IBlogNewsRecallService {
    @Autowired
    private BlogNewsRecallMapper blogNewsRecallMapper;

    @Autowired
    private SysFileMapper sysFileMapper;

    /**
     * 查询朝花夕拾
     *
     * @param id 朝花夕拾主键
     * @return 朝花夕拾
     */
    @Override
    public BlogNewsRecall selectBlogNewsRecallById(String id) {
        blogNewsRecallMapper.updateViewNumber(id);
        BlogNewsRecall newsRecall = blogNewsRecallMapper.selectBlogNewsRecallById(id);
        if (StringUtils.isNotEmpty(newsRecall.getImageId())) {
            SysFile sysFile = sysFileMapper.selectSysFileById(newsRecall.getImageId());
            newsRecall.setSysFile(sysFile);
        }
        return newsRecall;
    }

    /**
     * 查询朝花夕拾列表
     *
     * @param blogNewsRecall 朝花夕拾
     * @return 朝花夕拾
     */
    @Override
    public List<BlogNewsRecall> selectBlogNewsRecallList(BlogNewsRecall blogNewsRecall) {
        List<BlogNewsRecall> recalls = blogNewsRecallMapper.selectBlogNewsRecallList(blogNewsRecall);
        for (BlogNewsRecall recall : recalls) {
            if (StringUtils.isNotEmpty(recall.getImageId())) {
                SysFile sysFile = sysFileMapper.selectSysFileById(recall.getImageId());
                recall.setSysFile(sysFile);
            }
        }
        return recalls;
    }
}
